<?php
/**
 * @Author:      dx
 * @DateTime:  2017-08-17 11:31:56
 * @Description: 把套餐卡支付超时的订单算成支付失败
 */
$api_service_path = __DIR__ . "/../../../api/";
ob_start();
require_once($api_service_path . "public/index.php");
ob_end_clean();

//微信支付 查找当前支付中的 支付时间超时的支付单
$wp=WeixinRecord::where("created_at","<",date("Y-m-d H:i:s",time()-2*60*60))->where("status",0)->get();
foreach ($wp as $_wp) {
    $_wp->status=2;
    $_wp->save();
    ServiceCardOrderPayRecord::where("order_id",$_wp->order_id)->update(array("status"=>2));
    ServiceCardOrder::where("order_id",$_wp->order_id)->update(array("status"=>'1310'));

    $sc_order_flows = new ServiceCardOrderFlow;
    $sc_order_flows->order_id = $_wp->order_id;
    $sc_order_flows->status =1310;
    $sc_order_flows->user_id = $_wp->user_id;
    $sc_order_flows->type = 'system';
    $sc_order_flows->save();

}

//还有一种情况是 没有选择支付方式 取消原始单
$sco=ServiceCardOrder::where('status','1011')->where("created_at","<",date("Y-m-d H:i:s",time()-2*60*60))->whereIn('order_source',array(2,10))->get();
foreach($sco as $_s){
    $_s->status = '1310';
    $_s->save();
    ServiceCardOrderPayRecord::where("order_id",$_s->order_id)->update(array("status"=>2));

    $sc_order_flows = new ServiceCardOrderFlow;
    $sc_order_flows->order_id = $_s->order_id;
    $sc_order_flows->status =1310;
    $sc_order_flows->user_id = $_s->user_id;
    $sc_order_flows->type = 'system';
    $sc_order_flows->save();
}

